package cc11001100.snakeyaml;

import org.yaml.snakeyaml.Yaml;

import java.io.InputStream;

/**
 * @author CC11001100
 */
public class TryCatchMain {

    /**
     * 解析给定路径的YAML文件
     *
     * @param yamlFilePath
     * @return
     */
    public static Object parse(String yamlFilePath) {
        try {
            Yaml yaml = new Yaml();
            InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(yamlFilePath);
            return yaml.load(inputStream);
        } catch (StackOverflowError e) {
            // ignored
        }
        return null;
    }

    public static void main(String[] args) {

        String filepath = "clusterfuzz-testcase-YamlFuzzer-4919139099082752";
        Object yamlObject = parse(filepath);
        if (yamlObject == null) {
            System.out.println("Yaml文件解析失败！");
            return;
        }
        // 判断非空后再使用
        System.out.println(yamlObject);

        // Output:
        // Yaml文件解析失败！

    }

}
